package com.agile.leetcode.concurrent.threadlocal;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 斐波那契哈希算法
 *
 * @Author KD
 * @Date 2021/1/14 9:40
 */
public class FibonacciHash {
    private static final int HASH_INCREMENT = 0x61c88647;
    private static AtomicInteger atomicInteger = new AtomicInteger();

    public static int hash() {
        return atomicInteger.getAndAdd(HASH_INCREMENT);
    }

    public static void main(String[] args) {
        int hashCode;
        for (int i = 0; i < 16; i++) {
            hashCode = i * HASH_INCREMENT + HASH_INCREMENT;
            int idx = hashCode & 15;
            System.out.println("斐波那契散列：" + idx + " 普通散列：" + (String.valueOf(i).hashCode() & 15));
        }
    }
}
